{% extends 'base.html' %}
{% load static %}

{% block title %}AI故事生成系统 - 首页{% endblock %}

{% block content %}
<div class="container mt-4">
    <!-- 欢迎横幅 -->
    <div class="jumbotron bg-light p-5 rounded-3 mb-4 shadow-sm">
        <h1 class="display-4">欢迎来到AI故事生成系统</h1>
        <p class="lead">使用AI技术创建独特的故事，或分享您自己的创作</p>
        
        <!-- 全站搜索 -->
        <div class="mt-4">
            <form method="get" action="/" class="d-flex">
                <input type="text" name="q" class="form-control form-control-lg me-2" placeholder="搜索故事..." aria-label="Search">
                <button class="btn btn-primary" type="submit">搜索</button>
            </form>
        </div>
        
        <!-- 分类导航 -->
        <div class="mt-4">
            <h5>按分类浏览:</h5>
            <div class="d-flex flex-wrap gap-2 mt-2">
                <a href="{% url 'story:list' %}" class="btn btn-outline-primary">全部</a>
                {% for category in categories %}
                <a href="{% url 'story:list' %}?category={{ category.id }}" class="btn btn-outline-primary">{{ category.name }}</a>
                {% endfor %}
            </div>
        </div>
    </div>
    
    <div class="row">
        <!-- 最新故事 -->
        <div class="col-md-6">
            <div class="card mb-4 shadow-sm">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="my-0">最新故事</h4>
                    <a href="{% url 'story:list' %}?sort_by=-created_at" class="btn btn-sm btn-outline-primary">查看更多</a>
                </div>
                <div class="card-body">
                    <div class="list-group list-group-flush">
                        {% for story in latest_stories %}
                        <a href="{% url 'story:detail' story.pk %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="mb-1">{{ story.title }}</h6>
                                <small class="text-muted">
                                    {% if story.category %}
                                    <span class="badge bg-primary">{{ story.get_category_display }}</span>
                                    {% endif %}
                                    {{ story.author.username }} | {{ story.created_at|date:"Y-m-d" }}
                                </small>
                            </div>
                            <span class="badge bg-primary rounded-pill">{{ story.views }} 阅读</span>
                        </a>
                        {% empty %}
                        <div class="text-center p-3">
                            <p class="text-muted">暂无故事</p>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 热门故事 -->
        <div class="col-md-6">
            <div class="card mb-4 shadow-sm">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="my-0">热门故事</h4>
                    <a href="{% url 'story:list' %}?sort_by=-likes" class="btn btn-sm btn-outline-primary">查看更多</a>
                </div>
                <div class="card-body">
                    <div class="list-group list-group-flush">
                        {% for story in popular_stories %}
                        <a href="{% url 'story:detail' story.pk %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="mb-1">{{ story.title }}</h6>
                                <small class="text-muted">
                                    {% if story.category %}
                                    <span class="badge bg-primary">{{ story.get_category_display }}</span>
                                    {% endif %}
                                    {{ story.author.username }} | {{ story.created_at|date:"Y-m-d" }}
                                </small>
                            </div>
                            <div>
                                <span class="badge bg-danger rounded-pill">
                                    <i class="bi bi-heart-fill"></i> {{ story.likes }}
                                </span>
                            </div>
                        </a>
                        {% empty %}
                        <div class="text-center p-3">
                            <p class="text-muted">暂无故事</p>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 行动号召 -->
    <div class="card text-center mt-2 mb-4 shadow-sm">
        <div class="card-body py-5">
            <h3>开始创作您的故事</h3>
            <p class="lead">使用传统方式编写或借助AI生成独特的故事内容</p>
            <div class="d-flex justify-content-center gap-3">
                <a href="{% url 'story:create' %}" class="btn btn-primary btn-lg">
                    <i class="bi bi-pen me-2"></i> 创建故事
                </a>
                <a href="{% url 'story:generate' %}" class="btn btn-success btn-lg">
                    <i class="bi bi-magic me-2"></i> AI生成故事
                </a>
            </div>
        </div>
    </div>
</div>
{% endblock %} 